<template>
	<view class="success-container">
		<!-- 导航栏 -->
		<nav-bar title="支付成功" :customBack="goHome">
			<template #right>
				<view @click="goHome" style="font-size: 28rpx; color: #5C4033;">首页</view>
			</template>
		</nav-bar>
		
		<!-- 页面内容 -->
		<view class="page-content has-nav-bar">
		
		<!-- 支付结果 -->
		<view class="result-section">
			<image src="/static/order/order-service.png" class="success-icon"></image>
			<text class="result-title">支付成功</text>
			<text class="result-desc">您的订单已支付成功，商家将尽快为您发货</text>
		</view>
		
		<!-- 订单信息 -->
		<view class="order-info">
			<view class="info-item">
				<text class="label">订单编号</text>
				<text class="value">{{orderInfo.id}}</text>
			</view>
			<view class="info-item">
				<text class="label">支付金额</text>
				<text class="value price">¥{{orderInfo.actualPrice}}</text>
			</view>
			<view class="info-item">
				<text class="label">支付方式</text>
				<text class="value">{{orderInfo.paymentMethod}}</text>
			</view>
			<view class="info-item">
				<text class="label">支付时间</text>
				<text class="value">{{formatDate(orderInfo.payTime)}}</text>
			</view>
		</view>
		
		<!-- 操作按钮 -->
		<view class="action-buttons">
			<button class="view-order-btn" @click="viewOrder">查看订单</button>
			<button class="continue-shopping-btn" @click="continueShopping">继续购物</button>
		</view>
		</view>
	</view>
</template>

<script>
import NavBar from '@/components/NavBar.vue';

export default {
	components: {
		NavBar
	},
		data() {
			return {
				orderId: '',
				orderInfo: {
					id: '',
					actualPrice: '0.00',
					paymentMethod: '',
					payTime: ''
				}
			}
		},
		onLoad(options) {
			// 获取订单ID
			if (options.orderId) {
				this.orderId = options.orderId;
				this.loadOrderInfo();
			}
		},
		methods: {
			// 加载订单信息
			loadOrderInfo() {
				// 从本地存储获取订单信息
				const orders = uni.getStorageSync('orders') || [];
				const order = orders.find(item => item.id === this.orderId);
				
				if (order) {
					this.orderInfo = order;
				} else {
					uni.showToast({
						title: '订单信息不存在',
						icon: 'none'
					});
				}
			},
			
			// 格式化日期
			formatDate(dateString) {
				if (!dateString) return '';
				
				const date = new Date(dateString);
				const year = date.getFullYear();
				const month = String(date.getMonth() + 1).padStart(2, '0');
				const day = String(date.getDate()).padStart(2, '0');
				const hours = String(date.getHours()).padStart(2, '0');
				const minutes = String(date.getMinutes()).padStart(2, '0');
				const seconds = String(date.getSeconds()).padStart(2, '0');
				
				return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
			},
			
			// 返回首页
			goHome() {
				uni.switchTab({
					url: '/pages/shop/index'
				});
			},
			
			// 查看订单
			viewOrder() {
				uni.navigateTo({
					url: `/pages/order/detail?id=${this.orderId}`
				});
			},
			
			// 继续购物
			continueShopping() {
				uni.switchTab({
					url: '/pages/shop/index'
				});
			}
		}
	}
</script>

<style lang="scss">
	.success-container {
		background-color: #f8f8f8;
		min-height: 100vh;
	}
	
	.navbar {
		display: flex;
		align-items: center;
		height: 90rpx;
		background-color: #fff;
		padding: 0 30rpx;
		position: relative;
		
		.navbar-left {
			display: flex;
			align-items: center;
			
			.back-icon {
				font-family: "iconfont";
				font-size: 36rpx;
				margin-right: 10rpx;
			}
			
			text {
				font-size: 28rpx;
				color: #333;
			}
		}
		
		.navbar-title {
			position: absolute;
			left: 50%;
			transform: translateX(-50%);
			font-size: 32rpx;
			font-weight: bold;
			color: #333;
		}
		
		.navbar-right {
			width: 100rpx;
		}
	}
	
	.result-section {
		background-color: #fff;
		padding: 60rpx 30rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		
		.success-icon {
			width: 120rpx;
			height: 120rpx;
			margin-bottom: 30rpx;
			}
			
		.result-title {
			font-size: 36rpx;
			font-weight: bold;
			color: #333;
			margin-bottom: 20rpx;
			}
			
		.result-desc {
			font-size: 28rpx;
			color: #666;
			text-align: center;
		}
	}
	
	.order-info {
		background-color: #fff;
		margin-top: 20rpx;
		padding: 30rpx;
		
		.info-item {
			display: flex;
			justify-content: space-between;
			margin-bottom: 20rpx;
			
			&:last-child {
				margin-bottom: 0;
			}
			
			.label {
				font-size: 28rpx;
				color: #666;
			}
			
			.value {
				font-size: 28rpx;
				color: #333;
				
				&.price {
					color: #FF6600;
					font-weight: bold;
				}
			}
		}
	}
	
	.action-buttons {
		margin-top: 60rpx;
		padding: 0 30rpx;
		display: flex;
		justify-content: space-between;
		
		button {
			width: 45%;
			height: 90rpx;
			line-height: 90rpx;
			font-size: 30rpx;
			border-radius: 45rpx;
		}
		
		.view-order-btn {
			background-color: #fff;
			color: #333;
			border: 1rpx solid #ddd;
		}
		
		.continue-shopping-btn {
			background-color: #FF6600;
			color: #fff;
		}
	}
</style>